﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Octgn.Data;

namespace Deck_Analyser
{
    public partial class fclsmain : Form
    {
        public fclsmain()
        {
            InitializeComponent();
        }
        private void closeToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            Properties.Settings.Default.Save();
            this.Close();
        }
        private void loadDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Show the Folder Browser to select OCTGN2 Games folder
            folderBrowserDialog1.ShowDialog();
            // load the data path to settings
            Properties.Settings.Default.DataPath = folderBrowserDialog1.SelectedPath;
            update(1); 
        }
        private void button1_Click(object sender, EventArgs e)
        {
            fclsAdv fclsAdv = new fclsAdv();
            fclsAdv.ShowDialog();
        }
        private void fclsmain_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.FirstRun == true)
            {
                Properties.Settings.Default.FirstRun = false;                
                folderBrowserDialog1.ShowDialog();
                Properties.Settings.Default.DataPath = folderBrowserDialog1.SelectedPath;                
                update(1);
            }
            update(1); 
        }
        public void update(int num)
        {

            if (num == 0)  // update all
            {
                update(1); update(2); 
                return;
            }
            else if (num == 1)  // update status label with DataPath
            {
                statusLabel.Text = "Data path loaded: " + Properties.Settings.Default.DataPath;
                return;
            }
            else if (num == 2)  // update status labe with resently loaded deck
            {
                statusLabel.Text = "Deck file loaded: " + listBox_Decklist.SelectedItem.ToString();
                return;
            }

        }
        private void loadDeckToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //set initial directory
            openFileDialog1.InitialDirectory = Properties.Settings.Default.DataPath + "\\Decks";
            
            //Show the Open File dialog to select a deck to load
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                FileInfo filename = new FileInfo(openFileDialog1.FileName);
                listBox_Decklist.Items.Add(filename.Name);
                listBox_Decklist.SelectedItem = filename.Name;                
                update(2);
            }
        }
        private void clearAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            listBox_Decklist.Items.Clear();
        }
        private void unloadDeckToolStripMenuItem_Click(object sender, EventArgs e)
        {
            listBox_Decklist.Items.Remove(listBox_Decklist.SelectedItem);
        }        
    }
}